package ar.edu.itba.it.paw.domain;

import java.util.Date;

public class Product extends PersistentAttributes {
	
	private String name;
	private String description;
	private Date release_date;
	private Category category;
	private float price;
	private int quantity;
	private boolean state;
	private int visits;
	private User owner;

	//This constructor is used to create products before they are inserted to the database.
	public Product( String name, String description, Date release_date ,Category category, float price, int quantity, boolean state, User owner){
		if(!(name == null || name.equals("") || description == null || description.equals("") || category == null || price < 0 || quantity < 0 )){
			this.name = name; 
			this.description = description;
			this.release_date = release_date;
			this.category = category;
			this.price = price;
			this.quantity = quantity;
			this.state = state;
			this.owner = owner;
		}else{
			throw new IllegalArgumentException("Invalid parameters");
		}
	}
	
	
	//This constructor is used to obtain products from the databse
	public Product(int product_id, String name, String description, Date release_date ,Category category, float price, int quantity, boolean state,int visits ,User owner){
		this(name,description,release_date,category,price,quantity,state,owner);
		if(product_id < 0){
			throw new IllegalArgumentException("Invalid User id");
		}
		this.setId(product_id);
		this.visits = visits;
			
	}

	public User getOwner() {
		return owner;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Date getRelease_date() {
		return release_date;
	}


	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public float getPrice() {
		return price;
	}


	public int getQuantity() {
		return quantity;
	}

	public boolean getState() {
		return state;
	}

	public void setState(boolean state) {
		this.state = state;
	}





	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result
		+ ((release_date == null) ? 0 : release_date.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Product other = (Product) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (release_date == null) {
			if (other.release_date != null)
				return false;
		} else if (!release_date.equals(other.release_date))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Product [name=" + name + ", description=" + description
				+ ", release_date=" + release_date + ", category=" + category
				+ ", price=" + price + ", quantity=" + quantity + ", state="
				+ state + ", visits=" + visits + ", owner=" + owner + "]";
	}

	public void setVisits(int visits) {
		this.visits = visits;
	}


	public int getVisits() {
		return visits;
	}

}